package com.jqsoft.launcher.util;

import android.content.Context;
import android.content.res.AssetManager;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
 * @author gujunqi
 * date：2014-1-15 
 */
public class AssetCopyUtil {
	private Context context;

	public AssetCopyUtil(Context context) {
		this.context = context;
	}

	public boolean copyFile(String srcfilename,File file){
		try {
			AssetManager am  = context.getAssets();
			InputStream is = am.open(srcfilename);
			file.getParentFile().mkdir();     
			file.createNewFile();
			FileOutputStream fos = new FileOutputStream(file);
			byte[] buffer = new byte[1024];
			int len=0;
			while((len = is.read(buffer))!=-1){
				fos.write(buffer, 0, len);
			}
			fos.flush();
			fos.close();
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
	}
}
